package gs.wicket.app.shop;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.model.Model;

import gs.wicket.app.account.Korisnik;
import gs.wicket.app.login.LogInPage;
import gs.wicket.app.product.AboutProduct;
import gs.wicket.app.product.Product;
import gs.wicket.app.product.ProductsPage;
import gs.wicket.app.session.GSSession;

public class Parfemi extends ProductsPage {

public Parfemi() {
	GSSession gsSession = (GSSession) getSession();
	Korisnik k = gsSession.getLogovanKorisnik();
	if (k==null){
		setResponsePage(LogInPage.class);
	}
		PageableListView products = new PageableListView("products", getParfumProducts(), 2) {

			private static final long serialVersionUID = 1L;

			@Override
		      protected void populateItem(ListItem item) {
		        Product product = (Product) item.getModelObject();
		        item.add(new Label("name", product.getName()));
		        Image image = new Image("image", new Model(product.getImageURL()));
		        
		        
		        PageParameters pars = new PageParameters();
		        pars.add("name", product.getName());
		        BookmarkablePageLink moinfl1 = new BookmarkablePageLink("moinfl1", AboutProduct.class, pars);
		        moinfl1.add(image);
		        item.add(moinfl1);
		        
		        
		     
		        item.add(new Label("description", product.getDescription()));//
		        item.add(new Label("price", "<b>" + product.getPrice()+ " EUR</b>").setEscapeModelStrings(false));
		        
		        BookmarkablePageLink book =new BookmarkablePageLink("moinfl", AboutProduct.class, pars);
		        book.add(new Label("parfemi.additional.info", getLangProperty("search.product.info")));
		        item.add(book);


		        item.add(new Link("add", item.getModel()) {

					private static final long serialVersionUID = 1L;
					{
						add(new Label("parfemi.add", getLangProperty("search.product.add")));
					}

				@Override
		          public void onClick() {
		            Product selected = (Product) getModelObject();
		            getCart().getProducts().add(selected);
		          }
		        });
		      }
		    };
		
		    add(products);
		    add(new PagingNavigator("navigator", products));
		    add(new Label("parfemi.title", getLangProperty("parfemi.title")));
		    add(new Label("parfemi.message", getLangProperty("search.product.message")));
		   
		}
}
